package com.example.makerspace.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.example.makerspace.config.SendMessageConfig;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


public class MessageUtils {

    private  static  String sendVect="SMS_284900281";
    public static void sendMessage(String phoneNumber,String templateCode) {
        String msg = "";
        Config config = new Config()
                .setAccessKeyId("LTAI5tDLVDm43ULckWZCFQKp")
                .setAccessKeySecret("ZcsunWCwi0fJaxiB1oBVHFtYwu9M1b");
        config.endpoint = "dysmsapi.aliyuncs.com";
        try {
            Client client = new Client(config);
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    .setSignName("长三角转化中心")
                    .setTemplateCode(templateCode)
                    .setPhoneNumbers(phoneNumber)
                    .setTemplateParam("{\"code\":\"1234\"}");
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
            msg = sendSmsResponse.getBody().message;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void sendMessages(String phone, String templateCode) {
        String msg = "";
        Config config = new Config()
                .setAccessKeyId("LTAI5tDLVDm43ULckWZCFQKp")
                .setAccessKeySecret("ZcsunWCwi0fJaxiB1oBVHFtYwu9M1b");
        config.endpoint = "dysmsapi.aliyuncs.com";
        try {
                Client client = new Client(config);
                SendSmsRequest sendSmsRequest = new SendSmsRequest()
                        .setSignName("长三角转化中心")
                        .setTemplateCode(templateCode)
                        .setPhoneNumbers(phone)
                        .setTemplateParam("{\"code\":\"1234\"}");
                SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
                msg = sendSmsResponse.getBody().message;

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String sendCaptcha(String phone,String validateCode) {
        String msg = "";
        Config config = new Config()
                .setAccessKeyId("LTAI5tDLVDm43ULckWZCFQKp")
                .setAccessKeySecret("ZcsunWCwi0fJaxiB1oBVHFtYwu9M1b");
        config.endpoint = "dysmsapi.aliyuncs.com";
        try {
            Client client = new Client(config);
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    .setSignName("长三角转化中心")
                    .setTemplateCode("SMS_462745532")
                    .setPhoneNumbers(phone)
                    .setTemplateParam("{\"code\":\""+validateCode+"\"}");
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
            msg = sendSmsResponse.getBody().message;
          return  msg;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void sendMessageCustomer() {
        String msg = "";
        Config config = new Config()
                .setAccessKeyId("LTAI5t7NvwgbvFUX8bCnh9X7")
                .setAccessKeySecret("efcq1Kz0QTuUnotVbbSsbIb4RZ7CcR");
        config.endpoint = "dysmsapi.aliyuncs.com";
        try {
            Client client = new Client(config);
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    .setSignName("盛石科技")
                    .setTemplateCode("SMS_467465050")
                    .setPhoneNumbers("18192396039");
                    // Request-level configuration rewrite, can set Http request parameters, etc.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
            msg = sendSmsResponse.getBody().message;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public static void main(String[] args) {
        String validateCode = ValidateCodeUtils.generateCodeNumber(4);
        //sendCaptcha("15970342814",validateCode);
        sendMessage("15970342814","SMS_472130183");

    }
}
